#include <stdio.h>
#include "stdlib.h"

typedef struct node {
    // 数据
    char data;
    // 指向下一个地址
    struct node *next;
} LinkStack;

// 初始化一个栈
LinkStack *init() {

    LinkStack *top;

    top = (LinkStack *) malloc(sizeof(LinkStack));

    top->data = 'a';
    top->next = NULL;

    return top;
}

// 进栈
LinkStack *push(LinkStack *top, char val) {

    LinkStack *node = (LinkStack *) malloc(sizeof(LinkStack));

    node->data = val;
    node->next = top;

    return node;
}

// 退出栈
LinkStack *pop(LinkStack *top) {

    LinkStack *node = top;

    LinkStack *next = top->next;
    // 释放头顶节点
    free(node);

    // 返回新头节点
    return next;
}

// 测试链式栈
int main() {

    LinkStack *top = init();

    printf("init top =%c \n", top->data);

    top = push(top, 'b');
    top = push(top, 'c');
    top = push(top, 'd');
    top = push(top, 'e');

    printf("push after top =%c \n", top->data);

    top = pop(top);
    printf("pop after top =%c \n", top->data);


    return 0;
}
